package cn.tianjindong.blog_portal.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.tianjindong.blog.common.pojo.PageView;
import cn.tianjindong.blog.mapper.BlogArticleMapper;
import cn.tianjindong.blog.pojo.BlogArticle;
import cn.tianjindong.blog.pojo.BlogArticleCategory;
import cn.tianjindong.blog.pojo.BlogArticleExample;
import cn.tianjindong.blog.pojo.BlogArticleExample.Criteria;
import cn.tianjindong.blog.pojo.BlogNotice;
import cn.tianjindong.blog.pojo.BlogNoticeExample;
import cn.tianjindong.blog_portal.service.ArticleService;

@Service
public class ArticleServiceImple implements ArticleService {

	@Autowired
	private BlogArticleMapper articleMapper;

	@Override
	public BlogArticle getArticleByIdAndAlias(Long id, String alias) {
		BlogArticle article = articleMapper.getArticleById(id);
		BlogArticleCategory category = null;
		if (article != null) {
			category = article.getCategory();
		}
		if (category != null && category.getAlias().equals(alias)) {
			return article;
		}
		return null;
	}

	@Override
	public BlogArticle getArticleById(Long id) {
		BlogArticle article = articleMapper.getArticleById(id);
		return article;
	}

	@Override
	public List<BlogArticle> getArticleListOrderByVisitNum(Integer countItem) {
		List<BlogArticle> list = articleMapper.getBriefListAndTabAndOrderByVisitNum(0, countItem);
		return list;
	}

	@Override
	public List<BlogArticle> getArticlePageView(Integer currentPage, Integer countItem) {
		// 查询时开始索引
		int startIndex = (currentPage - 1) * countItem;
		List<BlogArticle> list = articleMapper.getBriefListAndTabAndOrderByUpdateTime(startIndex, countItem);
		return list;
	}

}
